package com.alumni_circle.mapper.home;

import com.alumni_circle.entity.home.News;
import com.alumni_circle.entity.home.VO.NewsViewVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


/**
 * @author 龙小虬
 * @since 2020-07-06 22:11
 */
public interface NewsMapper extends BaseMapper<News> {

    @Select("SELECT news.title,news.content,news.id,news.picture,news.create_time\n" +
            "FROM user_news,news,user\n" +
            "WHERE user_news.news_id = news.id and news.state = '0' and user.id = user_news.user_id\n" +
            "and user.id = #{id} " +
            "ORDER BY create_time DESC")
    List<NewsViewVO> selectMyListNews(@Param("id") String id);

    @Select("SELECT news.title,news.content,news.id,news.picture,news.create_time\n" +
            "FROM user_news,news,user\n" +
            "WHERE user_news.news_id = news.id and news.state = '0' and user.id = user_news.user_id\n" +
            "and (news.title like concat ('%',#{search},'%') or news.content like concat('%',#{search},'%')) \n"+
            "and user.id = #{id} " +
            "ORDER BY create_time DESC")
    List<NewsViewVO> searchMyListNews(@Param("id") String id,@Param("search")String search);

    @Select("SELECT news.title,news.content,news.id,news.picture,news.create_time,user.`name`,`user`.icon\n" +
            "FROM user_news,news,user\n" +
            "WHERE user_news.news_id = news.id and news.state = '0' and user.id = user_news.user_id\n" +
            "ORDER BY create_time DESC")
    List<NewsViewVO> getAllNews();
}
